package com.meituan.catering.management.shop.biz.model.converter;

import com.meituan.catering.management.common.model.biz.PageBO;
import com.meituan.catering.management.shop.biz.model.ShopBO;
import com.meituan.catering.management.shop.biz.model.request.SearchShopBizRequest;
import com.meituan.catering.management.shop.dao.model.ShopDO;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Believe
 * Date 2022/5/17 9:35
 */
public class PageBOConverter {
    private static final Integer DEFAULT_PAGE_SIZE = 10;

    public static PageBO<ShopBO> toPageBO(List<ShopDO> list, SearchShopBizRequest request, Integer countAll){
        PageBO<ShopBO> pageBO = new PageBO<>();
        List<ShopBO> shopBOList = new ArrayList<>();
        for (ShopDO shopDO : list) {
            shopBOList.add(ShopBOConverter.toShopBO(shopDO));
        }
        pageBO.setRecords(shopBOList);
        pageBO.setPageSize(request.getPageSize());
        pageBO.setPageIndex(request.getPageIndex());
        pageBO.setTotalCount(countAll);
        if (countAll % DEFAULT_PAGE_SIZE == 0){
            pageBO.setTotalPageCount(countAll / DEFAULT_PAGE_SIZE);
        }else {
            pageBO.setTotalPageCount(countAll / DEFAULT_PAGE_SIZE + 1);
        }
        return pageBO;
    }

}
